package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dyqstart
 * @create 2021-09-03-15:00
 * @since 1.0.0
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    @Override
    public Map<String, Object> getSupplierList(Integer page,Integer rows,String supplierName) {
        Integer total = supplierDao.getCount();

        List<Supplier> list = supplierDao.getSupplierList(page,rows,supplierName);

        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("rows",list);

        return map;
    }

    @Override
    public void saveOrUpdateSupplierInfo(Supplier supplier,Integer supplierId) {
        if (supplierId == null){
            //添加供应商
            supplierDao.saveSupplier(supplier);
        }else {
            //修改供应商
            supplierDao.updateSupplier(supplier,supplierId);
        }
    }

    @Override
    public void deleteSupplier(String ids) {
        String[] split = ids.split(",");
        supplierDao.deleteSupplierByIds(split);
    }
}
